package algorithm;

public class leetcode_1094 {
    public boolean carPooling(int[][] trips, int capacity) {
        int[] diff = new int[1002];
        for(int[] trip:trips){
            diff[trip[1]]+=trip[0];
            diff[trip[2]]-=trip[0];
        }
        int number = 0;
        for(int i=0;i<1002;++i){
            number+=diff[i];
            if(number>capacity) return false;
        }
        return true;
    }
}
